;+
; NAME:
;       FLUX2TAU_BGPS
;
; PURPOSE:
;       Calculate the conversion between BGPS 1.1mm dust continuum emission
;       and an 8-micron dust optical depth (for use with GLIMPSE data).
;
; CATEGORY:
;       distance-omnibus utility routine
;
; CALLING SEQUENCE:
;       gamma = FLUX2TAU_BGPS( Td )
;
; INPUTS:
;       Td    -- Dust temperature (scalar or vector)
;
; OPTIONAL INPUTS:
;       NONE
;
; KEYWORD PARAMETERS:
;       APPER -- Use a "beam size" of the 40" Bolocat aperture
;                rather than the native beam size of the BGPS.
;       MJY   -- Output GAMMA is in unity of ** inverse mJy **
;                (Default: inverse Jy)
;
; OUTPUTS:
;       GAMMA -- The conversion factor (** in units of inverse Jy **) to be
;                multiplied by 1.1mm flux density to obtain an 8-micron
;                optical depth.
;
; OPTIONAL OUTPUTS:
;       NONE
;
; MODIFICATION HISTORY:
;
;       Created,  03/07/11, TPEB -- Initial codified version.
;       Modified, 03/21/11, TPEB -- Clarified documentation re: vector
;                                   Td
;       Modified: 07/22/11, TPEB -- New routine for use with BGPS
;                                   (rather than IRAM) data.
;       Modified: 09/08/11, TPEB -- Moved BGPS-specific version of
;                                   GAMMA routine from
;                                   irdc_dist_model/ to utils/ and
;                                   renamed for use with the IRDC
;                                   morphological matching scheme.
;                                   Made routine a little more
;                                   functional.
;       Modified: 08/08/12, TPEB -- Updated kappa_8 with
;                                   newly-calculated value, and code
;                                   cleanup.
;       Modified: 09/06/12, TPEB -- Trying OH5 kappa_8 again -- with
;                                   new IRAC Band 4 scattering
;                                   correction.
;-

FUNCTION FLUX2TAU_BGPS, Td, APPER=apper, MJY=mjy
  
  COMPILE_OPT OBSOLETE
  
  ;; Parse keywords
  ;; 40" = 24.24 pixels, beam = 23.80 pixels
  dilute = keyword_set( apper ) ? 24.24d / 23.80d  : 1.d
  units  = keyword_set( mjy )   ? 1.d3             : 1.d
  
  ;; Define dust opacities used in this conversion (cm^2 / g)
  ;; opactiy per gram of DUST AND GAS -- GAS:DUST = 100:1)
  kappa_1 = 1.14d                    ;; OH5 dust opacity at 1.1mm (271.1 GHz)
  ;;kappa_8 = 1151.d                   ;; OH5 dust opactiy at 7.872um
  kappa_8 = 825.d                    ;; WD01 -- R=5.5A, Modified by D03
  
  Rk = kappa_8 / kappa_1             ;; Ratio of dust opacities
  omega = 2.902d-8 * dilute          ;; solid angle of BGPS beam / aperture
  
  ;; ;;=============================
  ;; ;; Fudge Factor to deal with uncertain kappa:
  ;; Rk *= 0.68831588d
  
  RETURN,Rk / (planck_mm(299.792458d / 271.1d, Td) * units * omega)
END
